<?php

/**
 * This is the model class for table "pemilik_wp".
 *
 * The followings are the available columns in table 'pemilik_wp':
 * @property string $nomor_induk
 * @property string $nama_pemilik
 * @property string $tanggal_lahir
 * @property string $tempat_lahir
 * @property string $jenis_kelamin
 * @property string $alamat_pemilik
 * @property string $rt
 * @property string $rw
 * @property string $kelurahan
 * @property string $kecamatan
 * @property string $kabupaten
 * @property string $warga_negara
 * @property string $kode_pos
 * @property string $status_aktif
 * @property string $tanggal
 * @property string $bukti_diri
 *
 * The followings are the available model relations:
 * @property WpBadanUsaha[] $wpBadanUsahas
 * @property WpPribadi[] $wpPribadis
 */
class PemilikWp extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'pemilik_wp';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nama_pemilik', 'required'),
			array('nomor_induk, bukti_diri', 'length', 'max'=>20),
			array('nama_pemilik', 'length', 'max'=>125),
			array('tempat_lahir, kelurahan, kecamatan, kabupaten', 'length', 'max'=>35),
			array('jenis_kelamin', 'length', 'max'=>1),
			array('alamat_pemilik', 'length', 'max'=>150),
			array('rt, rw', 'length', 'max'=>3),
			array('warga_negara', 'length', 'max'=>5),
			array('kode_pos', 'length', 'max'=>10),
			array('status_aktif', 'length', 'max'=>2),
			array('tanggal_lahir, tanggal', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('nomor_induk, nama_pemilik, tanggal_lahir, tempat_lahir, jenis_kelamin, alamat_pemilik, rt, rw, kelurahan, kecamatan, kabupaten, warga_negara, kode_pos, status_aktif, tanggal, bukti_diri', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'wpBadanUsahas' => array(self::HAS_MANY, 'WpBadanUsaha', 'nomor_induk'),
			'wpPribadis' => array(self::HAS_MANY, 'WpPribadi', 'nomor_induk'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'nomor_induk' => 'Nomor Induk',
			'nama_pemilik' => 'Nama Pemilik',
			'tanggal_lahir' => 'Tanggal Lahir',
			'tempat_lahir' => 'Tempat Lahir',
			'jenis_kelamin' => 'Jenis Kelamin',
			'alamat_pemilik' => 'Alamat Pemilik',
			'rt' => 'Rt',
			'rw' => 'Rw',
			'kelurahan' => 'Kelurahan',
			'kecamatan' => 'Kecamatan',
			'kabupaten' => 'Kabupaten',
			'warga_negara' => 'Warga Negara',
			'kode_pos' => 'Kode Pos',
			'status_aktif' => 'Status Aktif',
			'tanggal' => 'Tanggal',
			'bukti_diri' => 'Bukti Diri',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('nomor_induk',$this->nomor_induk,true);
		$criteria->compare('nama_pemilik',$this->nama_pemilik,true);
		$criteria->compare('tanggal_lahir',$this->tanggal_lahir,true);
		$criteria->compare('tempat_lahir',$this->tempat_lahir,true);
		$criteria->compare('jenis_kelamin',$this->jenis_kelamin,true);
		$criteria->compare('alamat_pemilik',$this->alamat_pemilik,true);
		$criteria->compare('rt',$this->rt,true);
		$criteria->compare('rw',$this->rw,true);
		$criteria->compare('kelurahan',$this->kelurahan,true);
		$criteria->compare('kecamatan',$this->kecamatan,true);
		$criteria->compare('kabupaten',$this->kabupaten,true);
		$criteria->compare('warga_negara',$this->warga_negara,true);
		$criteria->compare('kode_pos',$this->kode_pos,true);
		$criteria->compare('status_aktif',$this->status_aktif,true);
		$criteria->compare('tanggal',$this->tanggal,true);
		$criteria->compare('bukti_diri',$this->bukti_diri,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return PemilikWp the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
